package org.studiox.graph.runtime.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.studiox.graph.runtime.service.GraphService;

import java.util.List;

@RestController
@RequestMapping(value = "/studiox/api/graph/runtime/v1/graph")
@Tag(name = "Graph API Interface", description = "Graph API 接口")
public class GraphController {

  @Autowired private GraphService graphService;

  @RequestMapping(value = "/vertex", method = RequestMethod.POST)
  public void addGraphVertex(@RequestParam(value = "unique", required = true) String unique) {
    graphService.addGraphVertex(unique);
  }

  @RequestMapping(value = "/vertices", method = RequestMethod.GET)
  public List<String> getAllGraphVertexUniqueNames() {
    return graphService.getAllGraphVertexUniqueNames();
  }

  @RequestMapping(value = "/edge", method = RequestMethod.POST)
  public void addGraphEdge(
      @RequestParam(value = "content", required = true) String content,
      @RequestParam(value = "sourceUnique", required = true) String sourceUnique,
      @RequestParam(value = "targetUnique", required = true) String targetUnique) {
    graphService.addGraphEdge(content, sourceUnique, targetUnique);
  }

  @RequestMapping(value = "/edges", method = RequestMethod.GET)
  public List<String> getGraphEdgeContentsBySourceTargetUnique(
      @RequestParam(value = "sourceUnique", required = true) String sourceUnique,
      @RequestParam(value = "targetUnique", required = true) String targetUnique) {
    return graphService.getGraphEdgeContentsBySourceTargetUnique(sourceUnique, targetUnique);
  }
}
